class Solution {
public:
    int longestOnes(vector<int>& nums, int k) 
    {
        int left = 0, right = 0;
        int res = INT_MIN;
        int windowCount = 0;

        while(right < nums.size())
        {
            if(nums[right] == 1)
            {
                windowCount++;
            }
            right++;

            while(right - left - windowCount > k)
            {
                if(nums[left] == 1)
                {
                    windowCount--;
                }
                left++;
            }

            res = max(res, right - left);
        }

        return res == INT_MIN ? 0 : res;
    }
};


